package yawning.mew.bear;

import yawning.mew.character.CharacterModel.AttackResult;
import yawning.mew.sim.SimulationAction;

public class BashAction implements SimulationAction {
	BearThreatSimulator mState;
	double mCooldownExpireTime = 0.0;

	BashAction(BearThreatSimulator state) {
		mState = state;
	}

	@Override
	public double perform() {
		int cost = mState.mModel.bashCost;

		if (!mState.hasRage(cost) && !mState.mOoCEv.isUp()) return SimulationAction.ACTION_FAIL;
		if (mCooldownExpireTime > mState.mSimEngine.getSimTime()) return SimulationAction.ACTION_FAIL;

		AttackResult result = mState.mModel.getFrontalYellowResult();

		if (result == AttackResult.MISS) {
			mNrBashMiss++;

			if (mState.mIsLogging) mState.mLog.log("Bash: MISS\n");
		} else if (result == AttackResult.DODGE) {
			mNrBashDodge++;

			if (mState.mIsLogging) mState.mLog.log("Bash: DODGE\n");
		} else if (result == AttackResult.PARRY) {
			mNrBashParry++;

			if (mState.mIsLogging) mState.mLog.log("Bash: PARRY\n");
		} else {
			if (mState.mIsLogging) mState.mLog.log("Bash\n");

			mState.mActiveTarget.getTargetStunEv().controlledStun(mState.mModel.bashStunDuration);
		}

		mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.bashCDDuration;

		mState.onRageLoss(cost);

		return 1.5;
	}

	int mNrBashMiss = 0;
	int mNrBashDodge = 0;
	int mNrBashParry = 0;
	int mNrBashHit = 0;
}
